﻿@{
    ViewBag.Title = this.Context.Request.QueryString["title"];
    Layout = "~/Views/Shared/_PageLayout.cshtml";
}

@section scripts
{
    @Scripts.Render("~/Scripts/swfupload")
    <script type="text/javascript">

        //挂接ExtJS准备完毕事件
        Ext.onReady
        (
            function () {
                //初始化快速提示
                Ext.QuickTips.init();

                //设置状态保存提供者（当前设置为Cookie）
                Ext.state.Manager.setProvider(Ext.create('Ext.state.CookieProvider', { path: _StatePath }));

                //用于记录当前记录
                var _CurrentRecord = undefined;

                //创建数据存储对象
                var store = Ext.create
                (
                    'Ext.data.Store',
                    {
                        pageSize: 20,
                        autoSync: false,
                        autoLoad: false,
                        root: 'data',
                        remoteFilter: true,
                        remoteSort: true,
                        sorters: [{ property: 'OrganizationName', direction: 'ASC' }],
                        model: 'Blacklist',
                        listeners:
                        {
                            //处理数据加载事件
                            load: function (store, records, successful, eOpts) {

                            }
                        },
                        proxy:
                        {
                            type: 'ajax',
                            batchActions: false,
                            url: spms.url.Action('List', 'Blacklist'),
                            reader:
                            {
                                type: 'json',
                                root: 'data'
                            },
                            listeners:
                            {
                                //处理代理异常
                                exception: spms.exception.HandleProxyError
                            }
                        }
                    }
                );

                //创建工具栏
                var toolbar = Ext.create
                (
                    'Ext.toolbar.Toolbar',
                    {
                        region: 'north',
                        layout: 'hbox',
                        border: 5,
                        height: 32,
                        border: '1 0 1 0',
                        margins: '0 0 0 0',
                        padding: '0 6 0 6',
                        items:
                        [
                            {
                                id: 'spms-cmd-refresh',
                                text: '刷新',
                                tooltip: '重新加载数据',
                                tooltipType: 'qtip',
                                iconCls: 'spms-icon-refresh',
                                cls: 'spms-page-menu-button',
                                listeners:
                                {
                                    click: OnRefresh
                                }
                            },
                            '-',
                            {
                                id: 'spms-cmd-add',
                                text: '上传黑名单',
                                tooltip: '上传黑名单',
                                tooltipType: 'qtip',
                                cls: 'spms-page-menu-button',
                                iconCls: 'spms-icon-add',
                                listeners:
                                {
                                    click: OnUpload
                                }
                            }
                        ]
                    }
                );

                //创建检索面板
                var search = Ext.create
                (
                    'Ext.panel.Panel',
                    {
                        region: 'north',
                        frame: false,
                        animCollapse: false,
                        iconCls: 'spms-icon-search',
                        stateful: true,
                        stateId: 'spms-blacklist-search-state',
                        collapsible: true,
                        collapseMode: 'header',
                        titleCollapse: true,
                        collapsed: true,
                        margin: '0 0 6 0',
                        layout: 'fit',
                        id: 'spms-panel-search',
                        cls: 'spms-page-card-detail',
                        border: true,
                        title: '检索',
                        listeners:
                        {
                            //挂接显示事件
                            show: function (win, options) {
                                //获得表单
                                var form = win.down('form');

                                //判断是否存在
                                if (form) {
                                    //重置内容
                                    form.getForm().reset();

                                    //设置焦点
                                    form.down('field').focus(false, 50);
                                }
                            }
                        },
                        items:
                        [
                            {
                                xtype: 'form',
                                frame: false,
                                autoScroll: true,
                                bodyPadding: 6,
                                bodyCls: 'spms-page-card-detail-form-body',
                                bodyBorder: false,
                                border: false,
                                layout:
                                {
                                    type: 'table',
                                    columns: 2,
                                    tableAttrs:
                                    {
                                        style:
                                        {
                                            width: '100%'
                                        },
                                        cellpadding: 6
                                    }
                                },
                                items:
                                [
                                    {
                                        xtype: 'fieldcontainer',
                                        width: '100%',
                                        defaultType: 'textfield',
                                        layout:
                                        {
                                            type: 'hbox',
                                            align: 'stretch'
                                        },
                                        padding: 0,
                                        border: 0,
                                        items:
                                        [
                                            {
                                                fieldLabel: '',
                                                minWidth: 140,
                                                maxLength: 160,
                                                xtype: 'checkbox',
                                                boxLabel: '账户:',
                                                cls: 'spms-card-checkbox',
                                                boxLabelCls: 'spms-card-checkbox-boxlabel',
                                                itemId: 'chkAccountID',
                                                allowBlank: true,
                                                value: true,
                                                inputValue: true,
                                                listeners:
                                                {
                                                    change: spms.event.OnCheckBoxLabelChange
                                                }
                                            },
                                            {
                                                fieldLabel: '',
                                                itemId: 'AccountID',
                                                flex: 1
                                            }
                                        ]
                                    },
                                    {
                                        xtype: 'fieldcontainer',
                                        width: '100%',
                                        defaultType: 'textfield',
                                        layout:
                                        {
                                            type: 'hbox',
                                            align: 'stretch'
                                        },
                                        padding: 0,
                                        border: 0,
                                        items:
                                        [
                                            {
                                                fieldLabel: '',
                                                minWidth: 140,
                                                maxLength: 160,
                                                xtype: 'checkbox',
                                                boxLabel: '单位名称:',
                                                cls: 'spms-card-checkbox',
                                                boxLabelCls: 'spms-card-checkbox-boxlabel',
                                                itemId: 'chkOrganizationName',
                                                allowBlank: true,
                                                value: true,
                                                inputValue: true,
                                                listeners:
                                                {
                                                    change: spms.event.OnCheckBoxLabelChange
                                                }
                                            },
                                            {
                                                fieldLabel: '',
                                                itemId: 'OrganizationName',
                                                flex: 1
                                            }
                                        ]
                                    },
                                    {
                                        xtype: 'fieldcontainer',
                                        width: '100%',
                                        defaultType: 'textfield',
                                        layout:
                                        {
                                            type: 'hbox',
                                            align: 'stretch'
                                        },
                                        padding: 0,
                                        border: 0,
                                        items:
                                        [
                                            {
                                                fieldLabel: '',
                                                minWidth: 140,
                                                maxLength: 160,
                                                xtype: 'checkbox',
                                                boxLabel: '营业执照编号:',
                                                cls: 'spms-card-checkbox',
                                                boxLabelCls: 'spms-card-checkbox-boxlabel',
                                                itemId: 'chkBusinesslicense_SN',
                                                allowBlank: true,
                                                value: true,
                                                inputValue: true,
                                                listeners:
                                                {
                                                    change: spms.event.OnCheckBoxLabelChange
                                                }
                                            },
                                            {
                                                fieldLabel: '',
                                                itemId: 'Businesslicense_SN',
                                                flex: 1
                                            }
                                        ]
                                    },
                                    {
                                        xtype: 'fieldcontainer',
                                        width: '100%',
                                        defaultType: 'textfield',
                                        layout:
                                        {
                                            type: 'hbox',
                                            align: 'stretch'
                                        },
                                        padding: 0,
                                        border: 0,
                                        items:
                                        [
                                            {
                                                fieldLabel: '',
                                                minWidth: 140,
                                                maxLength: 160,
                                                xtype: 'checkbox',
                                                boxLabel: '组织结构代码证号:',
                                                cls: 'spms-card-checkbox',
                                                boxLabelCls: 'spms-card-checkbox-boxlabel',
                                                itemId: 'chkOrganizationCodeCertificate_SN',
                                                allowBlank: true,
                                                value: true,
                                                inputValue: true,
                                                listeners:
                                                {
                                                    change: spms.event.OnCheckBoxLabelChange
                                                }
                                            },
                                            {
                                                fieldLabel: '',
                                                itemId: 'OrganizationCodeCertificate_SN',
                                                flex: 1
                                            }
                                        ]
                                    },
                                    {
                                        xtype: 'fieldcontainer',
                                        width: '100%',
                                        defaultType: 'textfield',
                                        layout:
                                        {
                                            type: 'hbox',
                                            align: 'stretch'
                                        },
                                        padding: 0,
                                        border: 0,
                                        items:
                                        [
                                            {
                                                fieldLabel: '',
                                                minWidth: 140,
                                                maxLength: 160,
                                                xtype: 'checkbox',
                                                boxLabel: '税务登记证号:',
                                                cls: 'spms-card-checkbox',
                                                boxLabelCls: 'spms-card-checkbox-boxlabel',
                                                itemId: 'chkTaxRegistrationCertificate_SN',
                                                allowBlank: true,
                                                value: true,
                                                inputValue: true,
                                                listeners:
                                                {
                                                    change: spms.event.OnCheckBoxLabelChange
                                                }
                                            },
                                            {
                                                fieldLabel: '',
                                                itemId: 'TaxRegistrationCertificate_SN',
                                                flex: 1
                                            }
                                        ]
                                    },
                                    {
                                        xtype: 'fieldcontainer',
                                        width: '100%',
                                        defaultType: 'textfield',
                                        layout:
                                        {
                                            type: 'hbox',
                                            align: 'stretch'
                                        },
                                        padding: 0,
                                        border: 0,
                                        items:
                                        [
                                            {
                                                fieldLabel: '',
                                                minWidth: 140,
                                                maxLength: 160,
                                                xtype: 'checkbox',
                                                boxLabel: '开户许可证号:',
                                                cls: 'spms-card-checkbox',
                                                boxLabelCls: 'spms-card-checkbox-boxlabel',
                                                itemId: 'chkAccountOpeningLicense_SN',
                                                allowBlank: true,
                                                value: true,
                                                inputValue: true,
                                                listeners:
                                                {
                                                    change: spms.event.OnCheckBoxLabelChange
                                                }
                                            },
                                            {
                                                fieldLabel: '',
                                                itemId: 'AccountOpeningLicense_SN',
                                                flex: 1
                                            }
                                        ]
                                    }
                                ],
                                dockedItems:
                                [
                                    {
                                        xtype: 'toolbar',
                                        dock: 'bottom',
                                        ui: 'footer',
                                        cls: 'spms-page-card-toolbar',
                                        padding: '0 6 12 0',
                                        items:
                                        [
                                            '->',
                                            {
                                                text: '检索',
                                                xtype: 'button',
                                                cls: 'spms-page-card-detail-toolbar-button',
                                                handler: function () {
                                                    //获得当前对象
                                                    var me = this;

                                                    //获得表单对象
                                                    var form = me.up('form');

                                                    //检查数据是否合法
                                                    if (form.getForm().isValid()) {
                                                        //清除过滤条件
                                                        store.filters.clear();

                                                        //生成过滤条件
                                                        var filters = new Array();

                                                        if (form.down('#chkAccountID').getValue()) {
                                                            //添加检索条件
                                                            filters.push({ property: 'AccountID@E', value: form.down('#AccountID').getValue() });
                                                        }

                                                        if (form.down('#chkOrganizationName').getValue()) {
                                                            //添加检索条件
                                                            filters.push({ property: 'OrganizationName@C', value: form.down('#OrganizationName').getValue() });
                                                        }

                                                        if (form.down('#chkBusinesslicense_SN').getValue()) {
                                                            //添加检索条件
                                                            filters.push({ property: 'Businesslicense_SN@C', value: form.down('#Businesslicense_SN').getValue() });
                                                        }

                                                        if (form.down('#chkOrganizationCodeCertificate_SN').getValue()) {
                                                            //添加检索条件
                                                            filters.push({ property: 'OrganizationCodeCertificate_SN@C', value: form.down('#OrganizationCodeCertificate_SN').getValue() });
                                                        }

                                                        if (form.down('#chkTaxRegistrationCertificate_SN').getValue()) {
                                                            //添加检索条件
                                                            filters.push({ property: 'TaxRegistrationCertificate_SN@C', value: form.down('#TaxRegistrationCertificate_SN').getValue() });
                                                        }

                                                        if (form.down('#chkAccountOpeningLicense_SN').getValue()) {
                                                            //添加检索条件
                                                            filters.push({ property: 'AccountOpeningLicense_SN@C', value: form.down('#AccountOpeningLicense_SN').getValue() });
                                                        }

                                                        //刷新数据
                                                        Refresh({ filters: filters });
                                                    }
                                                }
                                            }
                                        ]
                                    }
                                ]
                            }
                        ]
                    }
                );

                //创建表格
                var grid = Ext.create
                (
                    'Ext.grid.Panel',
                    {
                        region: 'center',
                        store: store,
                        stateful: true,
                        border: true,
                        cls: 'spms-grid',
                        stateId: 'spms-blacklist-grid-state',
                        id: 'spms-card-grid',
                        forceFit: true,
                        autoScroll: true,
                        columnLines: true,
                        enableLocking: false,
                        unlockText: spms.resources.text_grid_column_unlock,
                        lockText: spms.resources.text_grid_column_lock,
                        viewConfig:
                        {
                            stripeRows: true,
                            loadingText: spms.resources.text_loading,
                            singleSelect: true
                        },
                        bbar: Ext.create
                            (
                            'SPMS.PagingToolbar',
                            {
                                store: store
                            }
                        ),
                        listeners:
                        {
                            select: OnRowSelect
                        },
                        columns:
                        [
                            {
                                text: '账户',
                                width: 120,
                                minWidth: 120,
                                sortable: true,
                                align: 'left',
                                dataIndex: 'AccountID',
                                hideable: false,
                                lockable: false
                            },
                            {
                                text: '单位名称',
                                width: 120,
                                minWidth: 120,
                                sortable: true,
                                align: 'left',
                                dataIndex: 'OrganizationName',
                                hideable: false,
                                lockable: false
                            },
                            {
                                text: '营业地址',
                                width: 120,
                                minWidth: 120,
                                sortable: true,
                                align: 'left',
                                dataIndex: 'BusinessAddress',
                                hideable: false,
                                lockable: false
                            },
                            {
                                text: '营业执照编号',
                                width: 120,
                                minWidth: 120,
                                sortable: true,
                                align: 'left',
                                dataIndex: 'Businesslicense_SN',
                                hideable: false,
                                lockable: false
                            },
                            {
                                text: '组织结构代码证号',
                                width: 120,
                                minWidth: 120,
                                sortable: true,
                                align: 'left',
                                dataIndex: 'OrganizationCodeCertificate_SN',
                                hideable: false,
                                lockable: false
                            },
                            {
                                text: '组织结构代码证号',
                                width: 120,
                                minWidth: 120,
                                sortable: true,
                                align: 'left',
                                dataIndex: 'OrganizationCodeCertificate_SN',
                                hideable: false,
                                lockable: false
                            },
                            {
                                text: '税务登记证号',
                                width: 120,
                                minWidth: 120,
                                sortable: true,
                                align: 'left',
                                dataIndex: 'OrganizationCodeCertificate_SN',
                                hideable: false,
                                lockable: false
                            },
                            {
                                text: '开户许可证号',
                                width: 120,
                                minWidth: 120,
                                sortable: true,
                                align: 'left',
                                dataIndex: 'AccountOpeningLicense_SN',
                                hideable: true
                            },
                            {
                                text: '法人身份证号',
                                width: 120,
                                minWidth: 120,
                                sortable: true,
                                align: 'left',
                                dataIndex: 'ArtificialPersonID',
                                hideable: true
                            },
                            {
                                text: '法人姓名',
                                width: 120,
                                minWidth: 120,
                                sortable: true,
                                align: 'left',
                                dataIndex: 'ArtificialPersonName',
                                hideable: true
                            },
                            {
                                text: '机构信用代码证',
                                width: 100,
                                minWidth: 100,
                                sortable: true,
                                align: 'left',
                                dataIndex: 'CreditAgenciesCodeCard',
                                hideable: true
                            }
                        ]
                    }
                );

                //创建布局
                var card = Ext.create
                (
                    'Ext.panel.Panel',
                    {
                        region: 'center',
                        layout: 'card',
                        border: false,
                        defaults:
                        {
                            border: false
                        },
                        bodyStyle: 'padding:6px',
                        items:
                        [
                            {
                                xtype: 'panel',
                                id: 'spms-card-list',
                                layout: 'border',
                                items:
                                [
                                    search,
                                    grid
                                ]
                            }
                        ]
                    }
                );

                //创建视口                
                var viewport = Ext.create
                (
                    'Ext.container.Viewport',
                    {
                        layout: 'border',
                        items:
                        [
                            {
                                region: 'north',
                                contentEl: 'spms-page-title',
                                border: false,
                                height: 48,
                                margins: '0 0 0 0'
                            },
                            toolbar,
                            card
                        ]
                    }
                );

                //加载数据
                store.load();

                //处理刷新按钮点击事件
                function OnRefresh(sender) {
                    //刷新数据
                    Refresh();
                }

                //处理新增按钮点击事件
                function OnUpload(sender) {
                    spms.common.UploadFile
                   (
                       {
                           file_types: '*.xls;*.xlsx',
                           file_types_description: 'Excel Files(*.xls;*.xlsx)',
                           file_size_limit: '10 MB',
                           file_size_limit_tip: '小于10MB的Excel文件',
                           callback: OnUploadExcelCallback,
                           url: spms.url.Action('Import', 'Blacklist')
                       }
                   );
                }

                //刷新数据
                function Refresh(options) {
                    //刷新数据
                    store.load(options);
                }

                //处理表格行选中事件
                function OnRowSelect(panel, record, index, options) {
                    //记录当前选中记录
                    _CurrentRecord = record;
                }

                function OnUploadExcelCallback(response, options) {
                    if (response.success) {
                        Ext.MessageBox.show({
                            title: spms.resources.text_upload_correct_title,
                            msg: "共有 " + response.data.count + " 条数据信息被成功导入！",
                            buttons: Ext.Msg.OK,
                            icon: Ext.Msg.INFO,
                            autoScroll: true,
                            closeAction: 'destroy'
                        });
                    }
                    else {
                        Ext.MessageBox.show({
                            title: spms.resources.text_upload_error_title,
                            msg: response.message,
                            buttons: Ext.Msg.OK,
                            icon: Ext.Msg.ERROR,
                            autoScroll: true,
                            closeAction: 'destroy'
                        });
                    }
                }
            }
        );

    </script>
}